package sudroid.json;

import java.io.IOException;
import java.io.Writer;

public class JSONWriter
{
  private static final int maxdepth = 20;
  private boolean comma = 0;
  protected char mode = 105;
  private JSONObject[] stack;
  private int top;
  protected Writer writer;

  public JSONWriter(Writer paramWriter)
  {
    JSONObject[] arrayOfJSONObject = new JSONObject[20];
    this.stack = arrayOfJSONObject;
    this.top = 0;
    this.writer = paramWriter;
  }

  private JSONWriter append(String paramString)
    throws JSONException
  {
    if (paramString == null)
      throw new JSONException("Null pointer");
    if ((this.mode == 111) || (this.mode == 97))
      try
      {
        if ((this.comma) && (this.mode == 97))
          this.writer.write(44);
        this.writer.write(paramString);
        if (this.mode == 111)
          this.mode = 107;
        this.comma = 1;
        return this;
      }
      catch (IOException localIOException)
      {
        throw new JSONException(localIOException);
      }
    throw new JSONException("Value out of sequence.");
  }

  private JSONWriter end(char paramChar1, char paramChar2)
    throws JSONException
  {
    if (this.mode != paramChar1)
    {
      JSONException localJSONException = new sudroid/json/JSONException;
      if (paramChar1 == 'o');
      for (String str = "Misplaced endObject."; ; str = "Misplaced endArray.")
      {
        localJSONException.<init>(str);
        throw localJSONException;
      }
    }
    pop(paramChar1);
    try
    {
      this.writer.write(paramChar2);
      this.comma = 1;
      return this;
    }
    catch (IOException localIOException)
    {
    }
    throw new JSONException(localIOException);
  }

  private void pop(char paramChar)
    throws JSONException
  {
    if (this.top <= 0)
      throw new JSONException("Nesting error.");
    JSONObject[] arrayOfJSONObject1 = this.stack;
    int i = this.top - 1;
    if (arrayOfJSONObject1[i] == 0);
    for (char c = 'a'; c != paramChar; c = 'k')
      throw new JSONException("Nesting error.");
    int j = this.top - 1;
    this.top = j;
    int k;
    if (this.top == 0)
      k = 100;
    while (true)
    {
      this.mode = k;
      return;
      JSONObject[] arrayOfJSONObject2 = this.stack;
      int m = this.top - 1;
      if (arrayOfJSONObject2[m] == 0)
      {
        k = 97;
        continue;
      }
      k = 107;
    }
  }

  private void push(JSONObject paramJSONObject)
    throws JSONException
  {
    if (this.top >= 20)
      throw new JSONException("Nesting too deep.");
    JSONObject[] arrayOfJSONObject = this.stack;
    int i = this.top;
    arrayOfJSONObject[i] = paramJSONObject;
    if (paramJSONObject == null);
    for (int j = 97; ; j = 107)
    {
      this.mode = j;
      int k = this.top + 1;
      this.top = k;
      return;
    }
  }

  public JSONWriter array()
    throws JSONException
  {
    if ((this.mode == 105) || (this.mode == 111) || (this.mode == 97))
    {
      push(null);
      JSONWriter localJSONWriter = append("[");
      this.comma = 0;
      return this;
    }
    throw new JSONException("Misplaced array.");
  }

  public JSONWriter endArray()
    throws JSONException
  {
    return end(97, 93);
  }

  public JSONWriter endObject()
    throws JSONException
  {
    return end(107, 125);
  }

  public JSONWriter key(String paramString)
    throws JSONException
  {
    if (paramString == null)
      throw new JSONException("Null key.");
    if (this.mode == 107)
      try
      {
        if (this.comma)
          this.writer.write(44);
        JSONObject[] arrayOfJSONObject = this.stack;
        int i = this.top - 1;
        JSONObject localJSONObject1 = arrayOfJSONObject[i];
        Boolean localBoolean = Boolean.TRUE;
        JSONObject localJSONObject2 = localJSONObject1.putOnce(paramString, localBoolean);
        Writer localWriter = this.writer;
        String str = JSONObject.quote(paramString);
        localWriter.write(str);
        this.writer.write(58);
        this.comma = 0;
        this.mode = 111;
        return this;
      }
      catch (IOException localIOException)
      {
        throw new JSONException(localIOException);
      }
    throw new JSONException("Misplaced key.");
  }

  public JSONWriter object()
    throws JSONException
  {
    if (this.mode == 105)
      this.mode = 111;
    if ((this.mode == 111) || (this.mode == 97))
    {
      JSONWriter localJSONWriter = append("{");
      JSONObject localJSONObject = new JSONObject();
      push(localJSONObject);
      this.comma = 0;
      return this;
    }
    throw new JSONException("Misplaced object.");
  }

  public JSONWriter value(double paramDouble)
    throws JSONException
  {
    Double localDouble = new Double(paramDouble);
    return value(localDouble);
  }

  public JSONWriter value(long paramLong)
    throws JSONException
  {
    String str = Long.toString(paramLong);
    return append(str);
  }

  public JSONWriter value(Object paramObject)
    throws JSONException
  {
    String str = JSONObject.valueToString(paramObject);
    return append(str);
  }

  public JSONWriter value(boolean paramBoolean)
    throws JSONException
  {
    if (paramBoolean);
    for (String str = "true"; ; str = "false")
      return append(str);
  }
}

/* Location:           D:\Program Files\eclipse\apktool-r01-3\新浪微博\classes.dex.dex2jar.jar
 * Qualified Name:     sudroid.json.JSONWriter
 * JD-Core Version:    0.6.0
 */